<?php $_ordersCollection = $block->getOrders();?>
<?php $_orders = $block->getOrdersByIncrementId($_ordersCollection);?>
<?php $incrementId = $block->getData('increment');?>
<?php $orderDuring = $block->getData('orderDuring');?>
<?=$block->getChildHtml('info')?>
<div class="form_left">
    <form class="form my_form" id="search_order_form" action="<?=$block->getUrl('sales/order/history');?>" method="get">
        <div class="order_no_txt">
            <input type="text" id="increment" name="increment" class="input-text" value=<?=$incrementId?>>
            <button type="submit" title="<?=$block->escapeHtmlAttr(__('Search'))?>" class="action search" aria-label="Search">
                <span><?=$block->escapeHtml(__('Search'))?></span>
            </button>
        </div>
    </form>
</div>
<div class="customer-welcome">
    <div
        data-mage-init='{"dropdown":{}}'
        data-toggle="dropdown"
        class="dropdown_list"
        data-action="customer-menu-toggle">
        <span> 
            <?php if ($orderDuring == 9): ?>
                所有订单
            <?php elseif ($orderDuring == 1): ?>
                一个月内
            <?php elseif ($orderDuring == 3): ?>
                三个月内
            <?php elseif ($orderDuring == 6): ?>
               半年内
            <?php else: ?>
                按订单时间搜索
            <?php endif;?>
        </span>
    </div>
    <ul data-target="dropdown" class="dropdown-options">
        <li class="item">
            <a href="<?= $this->getUrl('sales/order/history', ['order_during' => 9]) ?>"><span>所有订单</span></a>
        </li>
        <li class="item">
            <a href="<?= $this->getUrl('sales/order/history', ['order_during' => 1]) ?>"><span>一个月内</span></a>
        </li>
        <li class="item">
            <a href="<?= $this->getUrl('sales/order/history', ['order_during' => 3]) ?>"><span> 三个月内</span></a>
        </li>
        <li class="item">
            <a href="<?= $this->getUrl('sales/order/history', ['order_during' => 6]) ?>"><span> 半年内</span></a>
        </li>
    </ul>
</div>
<?php if ($_orders && count($_orders)): ?>
    <div class="clear" style="clear:both"></div>
    <div class="table-wrapper orders-history">
        <table class="data table table-order-items history" id="my-orders-table">
            <caption class="table-caption"><?=$block->escapeHtml(__('Orders'))?></caption>
            <thead>
                <tr>
                    <th scope="col" class="col id"><?=$block->escapeHtml(__('Order #'))?></th>
                    <th scope="col" class="col date"><?=$block->escapeHtml(__('Date'))?></th>
                    <?=$block->getChildHtml('extra.column.header')?>
                    <th scope="col" class="col shipping"><?=$block->escapeHtml(__('Ship To'))?></th>
                    <th scope="col" class="col total"><?=$block->escapeHtml(__('Order Total'))?></th>
                    <th scope="col" class="col status"><?=$block->escapeHtml(__('Status'))?></th>
                    <th scope="col" class="col actions"><?=$block->escapeHtml(__('Action'))?></th>
                    <th scope="col" class="col actions"><?=$block->escapeHtml(__('Payment Method'))?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($_orders as $_order): ?>
                    <?php $_items = $_order->getAllItems(); ?>
                    <tr class="product-order-main">
                        <td data-th="<?=$block->escapeHtmlAttr(__('Order #'))?>" class="col id"><?=$block->escapeHtml($_order->getRealOrderId())?></td>
                        <td data-th="<?=$block->escapeHtmlAttr(__('Date'))?>" class="col date"><?=/* @noEscape */$block->formatDate($_order->getCreatedAt())?></td>
                        <?php $extra = $block->getChildBlock('extra.container');?>
                        <?php if ($extra): ?>
                            <?php $extra->setOrder($_order);?>
                            <?=$extra->getChildHtml()?>
                        <?php endif;?>
                        <td data-th="<?=$block->escapeHtmlAttr(__('Ship To'))?>" class="col shipping"><?=$_order->getShippingAddress() ? $block->escapeHtml($_order->getShippingAddress()->getName()) : '&nbsp;'?></td>
                        <td data-th="<?=$block->escapeHtmlAttr(__('Order Total'))?>" class="col total"><?=/* @noEscape */$_order->formatPrice($_order->getGrandTotal())?></td>
                        <td data-th="<?=$block->escapeHtmlAttr(__('Status'))?>" class="col status"><?=$block->escapeHtml($_order->getStatusLabel())?></td>
                        <td data-th="<?=$block->escapeHtmlAttr(__('Actions'))?>" class="col actions">
                            <a href="<?=$block->escapeUrl($block->getViewUrl($_order))?>" class="action view">
                                <span><?=$block->escapeHtml(__('View Order'))?></span>
                            </a>
                            <?php if ($this->helper(\Magento\Sales\Helper\Reorder::class)->canReorder($_order->getEntityId())): ?>
                                <a href="#" data-post='<?=/* @noEscape */
                                $this->helper(\Magento\Framework\Data\Helper\PostHelper::class)
                                ->getPostData($block->getReorderUrl($_order))
                                ?>' class="action order">
                                    <span><?=$block->escapeHtml(__('Reorder'))?></span>
                                </a>
                            <?php endif?>
                        </td>
                        <td data-th="<?=$block->escapeHtmlAttr(__('Payment Method'))?>" class="col status"><?=$block->escapeHtml($_order->getPayment()->getMethodInstance()->getTitle())?></td>
                    </tr>

                    <?php foreach ($_items as $_item): ?>
                        <?php
                            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                            $_imagehelper  = $objectManager->get('Magento\Catalog\Helper\Image');
                            $product = $_item->getProduct();
                            if ($product) {
                                $productImage = $_imagehelper->init($product, 'category_page_list', array('height' => 350 , 'width'=> 350))->getUrl();
                            }
                        ?>
                        <tr>
                            <td></td>
                            <td class="col image">
                                <?php if ($product) :?>
                                    <img src="<?=$productImage?>"/>
                                <?php endif; ?>
                            </td>
                            <td class="col name" colspan="2"><?=$_item->getData("name")?></td>
                            <td class="col price center-align">価格:<br/><?=$_order->formatPrice($_item->getData("price"))?></td>
                            <td class="col qty center-align">個数:<br/><?=(float)$_item->getData("qty_ordered")?></td>
                            <td class="col total center-align">小計:<br/><?=$_order->formatPrice($_item->getData("row_total"))?></td>
                        </tr>
                    <?php endforeach;?>

                <?php endforeach;?>
            </tbody>
        </table>
    </div>
    <?php if ($block->getPagerHtml()): ?>
        <div class="order-products-toolbar toolbar bottom"><?=$block->getPagerHtml()?></div>
    <?php endif?>
<?php else: ?>
    <div class="message info empty"><span><?=$block->escapeHtml(__('You have placed no orders.'))?></span></div>
<?php endif?>